PROGRAM SpeakFile(f);

{$R-}
{$M+}
{$X-}

{    A quick and dirty program to read a file out loud.  The file must be named
     "TextToSpeak" and reside on the default drive.  The program reads 5120
     characters from this file and sends that string thru the Reader English to
     phonetics converter.  The output from Reader is then sent thru the MacinTalk
     speech synthesizer.  The input file is assumed to be terminated by a "##".
     Only the SpeechOn error code is checked.  THIS PROGRAM IS INTENDED ONLY AS A
     DEMONSTRATION OF HOW TO SETUP AND CALL THE SPEECH SYNTHESIZER, AND DOES
     NOT CONFIRM TO MACINTOSH'S USER INPUT STYLE.                               }



{**** You must include these USES statements ****}

USES
     {$U Obj/MemTypes   }     MemTypes,
     {$U Obj/QuickDraw  }     QuickDraw,
     {$U Obj/OSIntf     }     OSIntf,
     {$U Obj/ToolIntf   }     ToolIntf,
     {$U Obj/PackIntf   }     PackIntf,
     {$U Obj/SpeechIntf }     SpeechIntf;




TYPE
   bytes = packed array[1..5120] of char;
   byteptr = ^bytes;


VAR
   i:                         INTEGER;
   linein:                    bytes;         {the English text to be spoken}
   lineptr:                   byteptr;       {a pointer to the text}
   f:                         file;          {for input file TextToSpeak}
   output:                    Handle;        {Handle to phonetic string}
   theSpeech:                 SpeechHandle;  {Handle to speech globals}


BEGIN

   i := SpeechOn('', theSpeech);             {Open the speech driver and the
                                              READER English to phonetics
                                              conversion package with the default
                                              pronounciation ruleset.}


   IF (i <> 0) THEN exit(SpeakFile);          {If error, go away}


   reset(f, 'TextToSpeak');                  {Open the English input file.}



   i := blockread(f, linein, 10);            {Read 10 blocks (5120 chars) from
                                              the input file.}


   lineptr := @linein;                       {Setup pointer to the English text.}


   output := NewHandle(0);                   {Create a handle for the phonetic
                                              output.  Reader will dynamically
                                              grow this handle as needed.}


               {Convert the English text to phonetic codes.}

   i := Reader(theSpeech, POINTER(lineptr), 6000, output);


   i := MacinTalk(theSpeech, output);        {Say it.}


   SpeechOff(theSpeech);                     {Close the speech driver.}


   DisposHandle(output);                     {Release the output handle}


   close(f)                                  {Close the input file.}

end.

